package com.example.service;

import com.example.dao.CustomerDao;
import com.example.dao.RuleDao;
import com.example.model.Customer;
import com.example.model.Rule;
import com.example.model.VipRule;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class DiscountService {

    @Autowired
    private CustomerDao customerDao;

    @Autowired
    private RuleDao ruleDao;

    public Customer getCustomer(String idCard){
        return customerDao.findByIdCard(idCard);
    }

    public Object getVipLevel(Object o){
        return null;
    }

    public BigDecimal discount(String vipLevel,String itemName,BigDecimal price) throws Exception{
        VipRule vipRule=ruleDao.findRulesByVipRuleLevel(vipLevel);
        List<Rule> ruleList = ruleDao.findRulesByVipRuleId(vipRule.getId());
        for (Rule rule : ruleList){
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String,Object> context = new DefaultContext<String, Object>();
            String express =rule.getExpress();
            context.put("价格",price);
            Object r = runner.execute(express.context,null,true,false);
            return BigDecimal.valueOf(Double.valueOf())
        }

}
